﻿using System.Collections.Generic;
using System.Linq;
using MvvmFx.Common.ViewModels;
using Pomodoro.ViewModels.Models;

namespace Pomodoro.ViewModels
{
    public static class PersonsLoader
    {
        public static SelectableCollection<PersonViewModel> Load()
        {
            // Load dummy bookings data.
            // nb. In a real app, this would go to a service to get the real data.
            //

            // Load collection data
            var persons = DataService.GetPersons();
            var personVMs = new SelectableCollection<PersonViewModel>();
            persons.ForEach(person =>
                                {

                                    var personVM = new PersonViewModel()
                                                       {
                                                           Name =
                                                               string.Format("{0} {1}", person.FirstName,
                                                                             person.LastName),
                                                           Role = person.Role,
                                                           Photo = person.Photo
                                                       };

                                    personVM.Tasks.AddRange(
                                        person.Tasks.Select(task => new TaskViewModel()
                                                                        {
                                                                            Key = task.Id.ToString(),
                                                                            Description = task.Description,
                                                                            NumberDone = task.Done,
                                                                            NumberEstimated = task.Estimated
                                                                        }).ToList());

                                    personVM.CurrentTask = personVM.Tasks[0].Description;
                                    personVMs.Add(personVM);
                                });

            personVMs[0].IsSelected = true;

            return personVMs;
        }
    }
}